package com.ruoyi.evaluate.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.base.domain.BaseStudent;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.evaluate.domain.EvaluateResults;
import com.ruoyi.evaluate.service.IEvaluateResultsService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价结果Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("评价结果信息管理")
@RestController
@RequestMapping("/evaluate/evalResults")
public class EvaluateResultsController extends BaseController
{
    @Autowired
    private IEvaluateResultsService evaluateResultsService;

    
    /**
     * 查询评价结果列表
     */
    @ApiOperation("获取评价结果列表")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:my')")
    @GetMapping("/my")
    public TableDataInfo my(EvaluateResults evaluateResults)
    {
    	evaluateResults.setStuId(SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<EvaluateResults> list = evaluateResultsService.selectEvaluateResultsList(evaluateResults);
        return getDataTable(list);
    }
    
    /**
     * 查询未评价学生列表
     */
    @ApiOperation("查询未评价学生列表")
    @GetMapping("/progress")
    public TableDataInfo progress(EvaluateResults evaluateResults)
    {
        startPage();
        List<BaseStudent> list = evaluateResultsService.selectUnEvaluateStudent(evaluateResults.getSemId());
        return getDataTable(list);
    }
    
    /**
     * 查询评价结果列表
     */
    @ApiOperation("获取评价结果列表")
    @GetMapping("/evaluate")
    public TableDataInfo evaluate(EvaluateResults evaluateResults)
    {
        List<EvaluateResults> list = evaluateResultsService.selectEvaluateList(evaluateResults);
        return getDataTable(list);
    }
    
    /**
     * 查询评价结果列表
     */
    @ApiOperation("获取评价结果列表")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluateResults evaluateResults)
    {
        startPage();
        List<EvaluateResults> list = evaluateResultsService.selectEvaluateResultsList(evaluateResults);
        return getDataTable(list);
    }

    /**
     * 导出评价结果列表
     */
    @ApiOperation("导出评价结果列表")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:export')")
    @Log(title = "评价结果", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EvaluateResults evaluateResults)
    {
        List<EvaluateResults> list = evaluateResultsService.selectEvaluateResultsList(evaluateResults);
        ExcelUtil<EvaluateResults> util = new ExcelUtil<EvaluateResults>(EvaluateResults.class);
        return util.exportExcel(list, "evalResults");
    }

    /**
     * 获取评价结果详细信息
     */
    @ApiOperation("获取评价结果详细信息")
    @ApiImplicitParam(name = "id", value = "评价结果ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(evaluateResultsService.selectEvaluateResultsById(id));
    }

    /**
     * 新增评价结果
     */
    @ApiOperation("新增评价结果")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:add')")
    @Log(title = "评价结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluateResults evaluateResults)
    {
        return toAjax(evaluateResultsService.insertEvaluateResults(evaluateResults));
    }
    
    /**
     * 计算结果
     */
    @ApiOperation("计算结果")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:add')")
    @ApiImplicitParam(name = "semId", value = "学期ID", required = true, dataType = "int", paramType = "path")
    @Log(title = "评价结果", businessType = BusinessType.INSERT)
    @GetMapping("/count/{semId}")
    public AjaxResult count(@PathVariable("semId") Long semId)
    {
        return toAjax(evaluateResultsService.countEvaluateResults(semId));
    }

    /**
     * 修改评价结果
     */
    @ApiOperation("修改评价结果")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:edit')")
    @Log(title = "评价结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluateResults evaluateResults)
    {
        return toAjax(evaluateResultsService.updateEvaluateResults(evaluateResults));
    }

    /**
     * 删除评价结果
     */
    @ApiOperation("删除评价结果")
    @ApiImplicitParam(name = "id", value = "评价结果ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('evaluate:evalResults:remove')")
    @Log(title = "评价结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluateResultsService.deleteEvaluateResultsByIds(ids));
    }
}
